package com.linran.javaweb.client;

import com.linran.javaweb.vo.User;
import com.linran.javaweb.vo.WebResult;
import feign.Headers;
import feign.Param;
import feign.RequestLine;

import java.util.List;

/**
 * https://www.jianshu.com/p/8376d709d972
 */
@Headers({"Accept: application/json","Host: web"})
public interface UserServiceClient {

    /**
     * GET Request Body 只有底层使用ApacheHttpClient，可以这么用
     * HttpURLConnection（JDK）：这种用法会将get方法自动转为post
     * OkHttpClient：这种用法会报错，method GET must not have a request body.
     * @param
     * @return
     */
    @RequestLine("GET /user/name")
    @Headers("Content-Type: application/json")
    WebResult<User> getUserInfo(User user);

    /**
     * GET Uri Template
     * @param name 使用@Param注解是将参数放在Uri Template中的占位符
     * @return
     */
    @RequestLine("GET /user/info?name={name}")
    @Headers("Content-Type: application/json")
    User getUserInfo(@Param("name") String name);

    /**
     * GET Uri Template
     * @param age
     * @param male
     * @return 返回复杂参数
     */
    @RequestLine("GET /users?age={age}&male={male}")
    @Headers("Content-Type: application/json")
    WebResult<List<User>> getUsers(@Param("age") Integer age, @Param("male") Boolean male);

    /**
     * POST Request Body
     * @param user feign中这种传递object（标准POJO）的方式，是将参数放在了Request Body中
     * @return
     */
    @RequestLine("POST /user")
    @Headers("Content-Type: application/json")
    WebResult<User> addUser(User user);

    /**
     * POST Uri Template 也可以
     * @param name
     * @return
     */
    @RequestLine("POST /name?name={name}")
    @Headers("Content-Type: application/json")
    WebResult<User> getName(@Param("name") String name);

    /**
     * PUT Uri Template
     * @param name
     * @param age
     * @return
     */
    @RequestLine("PUT /user/{name}?age={age}")
    @Headers("Content-Type: application/json")
    WebResult<User> updateUser(@Param("name") String name, @Param("age") Integer age);

    /**
     * PUT Request Body
     * @param User
     * @return
     */
    @RequestLine("PUT /user/info")
    @Headers("Content-Type: application/json")
    WebResult<User> updateUserOne(User User);

    /**
     * DELETE Uri Template
     * @param name
     * @return
     */
    @RequestLine("DELETE /user/{name}")
    @Headers("Content-Type: application/json")
    WebResult<User> deleteUser(@Param("name") String name);

    /**
     * DELETE Request Body
     * @param User
     * @return
     */
    @RequestLine("DELETE /user/info")
    @Headers("Content-Type: application/json")
    WebResult<User> deleteUserOne(User User);
}
